package service

import (
	"gin-vue-admin/global"
	"gin-vue-admin/model"
	"gin-vue-admin/model/request"
)

//@author: [piexlmax](https://github.com/piexlmax)
//@function: CreateLinesTails
//@description: 创建LinesTails记录
//@param: linesTails model.LinesTails
//@return: err error

func CreateLinesTails(linesTails model.LinesTails) (err error) {
	err = global.GVA_DB.Create(&linesTails).Error
	return err
}

//@author: [piexlmax](https://github.com/piexlmax)
//@function: DeleteLinesTails
//@description: 删除LinesTails记录
//@param: linesTails model.LinesTails
//@return: err error

func DeleteLinesTails(linesTails model.LinesTails) (err error) {
	err = global.GVA_DB.Delete(&linesTails).Error
	return err
}

//@author: [piexlmax](https://github.com/piexlmax)
//@function: DeleteLinesTailsByIds
//@description: 批量删除LinesTails记录
//@param: ids request.IdsReq
//@return: err error

func DeleteLinesTailsByIds(ids request.IdsReq) (err error) {
	err = global.GVA_DB.Delete(&[]model.LinesTails{},"id in ?",ids.Ids).Error
	return err
}

//@author: [piexlmax](https://github.com/piexlmax)
//@function: UpdateLinesTails
//@description: 更新LinesTails记录
//@param: linesTails *model.LinesTails
//@return: err error

func UpdateLinesTails(linesTails model.LinesTails) (err error) {
	err = global.GVA_DB.Save(&linesTails).Error
	return err
}

//@author: [piexlmax](https://github.com/piexlmax)
//@function: GetLinesTails
//@description: 根据id获取LinesTails记录
//@param: id uint
//@return: err error, linesTails model.LinesTails

func GetLinesTails(id uint) (err error, linesTails model.LinesTails) {
	err = global.GVA_DB.Where("id = ?", id).First(&linesTails).Error
	return
}

//@author: [piexlmax](https://github.com/piexlmax)
//@function: GetLinesTailsInfoList
//@description: 分页获取LinesTails记录
//@param: info request.LinesTailsSearch
//@return: err error, list interface{}, total int64

func GetLinesTailsInfoList(info request.LinesTailsSearch) (err error, list interface{}, total int64) {
	limit := info.PageSize
	offset := info.PageSize * (info.Page - 1)
    // 创建db
	db := global.GVA_DB.Model(&model.LinesTails{})
    var linesTailss []model.LinesTails
    // 如果有条件搜索 下方会自动创建搜索语句
	err = db.Count(&total).Error
	err = db.Limit(limit).Offset(offset).Find(&linesTailss).Error
	return err, linesTailss, total
}